package web

import (
	"github.com/gookit/validate"
	"ksd-social-api/commons/base/controller"
	"ksd-social-api/modules/common/aliplayer"
	"ksd-social-api/modules/common/aliplayer/context"
)

type AliplayerController struct {
	controller.BaseController
}

/**
 * @author feige
 * @date 2023-10-09
 * @version 1.0
 * @desc 获取视频播放码
 */
func (web *AliplayerController) GetPlayAuth() {
	// 1: 绑定传递过来的参数
	var aliPlayerContext context.AliPlayerContext
	web.BindJSON(&aliPlayerContext)
	// 2: 开始验证参数
	validation := validate.Struct(aliPlayerContext)
	if !validation.Validate() {
		web.FailWithValidatorData(validation)
		return
	}
	auth, err := aliplayer.GetPlayAuth(aliPlayerContext.Vid)
	if err != nil {
		web.FailCodeMsg(908, "视频解析失败!")
		return
	}

	web.Ok(auth)
}

/**
 * @author feige
 * @date 2023-10-09
 * @version 1.0
 * @desc 获取视频播放链接
 */
func (web *AliplayerController) GetPlayLink() {
	// 1: 绑定传递过来的参数
	var aliPlayerContext context.AliPlayerContext
	web.BindJSON(&aliPlayerContext)
	// 2: 开始验证参数
	validation := validate.Struct(aliPlayerContext)
	if !validation.Validate() {
		web.FailWithValidatorData(validation)
		return
	}
	link, err := aliplayer.GetPlayLink(aliPlayerContext.Vid)
	if err != nil {
		web.FailCodeMsg(908, "视频解析失败!")
		return
	}

	web.Ok(link)
}

/**
 * @author feige
 * @date 2023-10-09
 * @version 1.0
 * @desc 获取视频播放链接
 */
func (web *AliplayerController) GetPlayLinkAll() {
	// 1: 绑定传递过来的参数
	var aliPlayerContext context.AliPlayerContext
	web.BindJSON(&aliPlayerContext)
	// 2: 开始验证参数
	validation := validate.Struct(aliPlayerContext)
	if !validation.Validate() {
		web.FailWithValidatorData(validation)
		return
	}
	auth, err := aliplayer.GetPlayLinkAll(aliPlayerContext.Vid)
	if err != nil {
		web.FailCodeMsg(908, "视频解析失败!")
		return
	}

	web.Ok(auth)
}

/**
 * @author feige
 * @date 2023-10-09
 * @version 1.0
 * @desc 获取视频播放权限码
 */
func (web *AliplayerController) GetPlayAuthAll() {
	// 1: 绑定传递过来的参数
	var aliPlayerContext context.AliPlayerContext
	web.BindJSON(&aliPlayerContext)
	// 2: 开始验证参数
	validation := validate.Struct(aliPlayerContext)
	if !validation.Validate() {
		web.FailWithValidatorData(validation)
		return
	}
	link, err := aliplayer.GetPlayAuthAll(aliPlayerContext.Vid)
	if err != nil {
		web.FailCodeMsg(908, "视频解析失败!")
		return
	}

	web.Ok(link)
}
